package com.alipay.app.groupmeal.standard.widget.business;

import android.content.Context;
import android.content.res.TypedArray;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.alipay.app.groupmeal.standard.R;

/**
 * @ProjectName: 团餐
 * @ClassName: BScreenTitleView
 * @Description: java类作用描述
 * @Author: bd-001935
 * @CreateDate: 4/14/22 4:40 PM
 * @UpdateUser: bd-001935
 * @UpdateDate: 4/14/22 4:40 PM
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class BScreenTitleView extends BaseBScreenView {

    private TextView mTvTitle;
    private String title;

    public BScreenTitleView(Context context) {
        this(context, null);
    }

    public BScreenTitleView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public BScreenTitleView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        setFocusable(false);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.view_presentation_title;
    }

    @Override
    public int[] getStyleableRes() {
        return R.styleable.BScreenTitleView;
    }

    @Override
    public void getAttrs(TypedArray ta) {
        super.getAttrs(ta);
        title = ta.getString(R.styleable.BScreenTitleView_title);
    }

    @Override
    protected void initView(View view) {
        mTvTitle = view.findViewById(R.id.tv_title);
    }

    @Override
    protected void initData() {
        mTvTitle.setText(title);
    }

    public void setTitle(String title) {
        this.title = title;
        post(new Runnable() {
            @Override
            public void run() {
                mTvTitle.setText(TextUtils.isEmpty(title) ? "" : title);
            }
        });
    }

}
